<template>
	<view class="content">
		<image src="../../static/logo.png" style="width: 300rpx;height: 300rpx;"></image>
		<!-- <view style="font-weight: 600;color: #000000;font-size: 38rpx;">
			生鲜速达
		</view> -->
		<button class="button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
			手机号快捷登录
		</button>
		<!-- <view class="xieyi">
			<u-checkbox v-model="checked" size="13" activeColor="#2FCC71" shape="circle"></u-checkbox>
			<view class="">
				我已阅读并同意<text style="color: #0083FF;">《用户服务协议》</text>和<text style="color: #0083FF;">《隐私权政策》</text>
			</view>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked: true,
			}
		},
		methods: {
			async getPhoneNumber(e) {
				if (!this.checked) {
					uni.showToast({
						title: '请同意协议',
						icon: 'none',
						mask: true
					})
					return
				}
				console.log(e);
				uni.showLoading({
					title: '登入中',
					mask: true
				})
				if (e.detail.errMsg == 'getPhoneNumber:ok') {
					const resa = await uni.login()
					console.log(resa[1].code);

					const openid = await this.$apis.user.getOpenid({
						code: resa[1].code
					})
					console.log(openid);
					const tel = await this.$apis.user.phoneApi({
						code: e.detail.code,
						openid: openid.data.userInfo.openid

					})

					console.log('tel', tel);
					uni.setStorageSync('openid', openid.data.openid)
					uni.setStorageSync('id', openid.data.userInfo.id)
					uni.setStorageSync('ck', openid.data.userInfo.warehouseName)
					uni.setStorageSync('phone', tel.data.phoneNumber)
					uni.setStorageSync('typeA', openid.data.userInfo.type)
					this.$store.commit('SET_ISLOGIN', 1)
					this.$store.commit('SET_USERINFO', openid.data.userInfo)
					// 		this.phone = tel.msg
					// 		this.isLogin = true
					// 		uni.setStorageSync('phone', tel.msg)
					uni.hideLoading()
					uni.reLaunch({
						url: '/pages/index/index'
					})
				} else {
					uni.hideLoading()
				}


			},
		}
	}
</script>

<style scoped>
	.content {
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
		padding-top: 200rpx;
		align-items: center;
	}

	.button {
		width: 688rpx;
		height: 68rpx;
		margin: 0;
		padding: 0;
		border: none;
		background-color: transparent;
		height: auto;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #2FCC71;
		color: #ffffff;
		margin-top: 190rpx;
	}

	button::after {
		border: none;
	}

	.xieyi {
		width: 688rpx;
		display: flex;
		align-items: center;
		margin-top: 48rpx;
		color: #999999;
		font-size: 23rpx;
	}
</style>